package com.apes.fico.engine.model;

import com.apes.fico.masterdata.gl.model.AccountingChart;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.fico.masterdata.gl.model.AccountingSystem;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @program: apestech
 * @description: 要素
 * @author: Chengxm
 * @create: 2019-01-24 15:53
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ElementChart.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "element_id, acc_system_id"),
        @Index(columnList = "element_id, element_value, acc_chart_id, acc_system_id", unique = true)})
public class ElementChart extends Model {
    public final static String CONST_TABLE_NAME = "fin_element_chart";
    @Id
    @Column(name = "id", length = 8)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "要素科目表")
    @Comment("编码")
    private String id;

    @Comment("科目体系")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "acc_system_id", referencedColumnName = "id", nullable = false)
    private AccountingSystem accountingSystem;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "element_id", referencedColumnName = "id")
    @Comment("要素")
    private Element element;

    @Column(name = "element_value", nullable = false)
    @Comment("要素值")
    private String elementValue;

    @Comment("末级科目")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "acc_chart_id", referencedColumnName = "id", nullable = false)
    private AccountingChart accountingChart;

    @Column(name = "note", nullable = false)
    @Comment("备注")
    private String note;

}
